﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/AdminMaster.master" Inherits="System.Web.Mvc.ViewPage<Eacademy.Domain.Models.AdminSubjectListViewModel>" %>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var mentorid = 0;
            var href = "";
            $(".subject a").click(function () {
                $(this).siblings(".mentors").slideToggle();
                return false;
            });
            $(".delete-subject-link").live("click", function (event) {
                event.preventDefault();
                var $link = $(this);
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 120,
                    modal: true,
                    position: 'fixed',
                    draggable: false,
                    buttons: {
                        "Continue": function () {
                            $(this).dialog("close");
                            $.post($link.attr("href"), null, reloadPage);
                        },
                        Cancel: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            });


            $(".mentor-name").live("click",function () {
                $("input", $(this).parent()).attr("checked", true);
            });

            $("#dialog-mentor-list").dialog({
                resizable: false,
                height: 160,
                modal: true,
                position: 'fixed',
                autoOpen: false,
                draggable: false,
                buttons: {
                    "Continue": function () {
                        mentorid = $("input[name='mentor']:checked").val()
                        $(this).dialog("close");
                        document.location.href = href + "?mentoruserid=" + mentorid;
                        //$.post(href, null, reloadPage);
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }
            });


            $(".choose-mentor").live("click", function (event) {
                event.preventDefault();
                var $link = $(this);
                href = $link.attr("href");
                var subjectId = $link.attr("id").replace(/\D/g, '');
                // $("#dialog-mentor-list").load("/admin/subjects/getmentorsbysubjectid/" + subjectId, null, function () {
                //     $("#dialog-mentor-list").dialog("open");
                // });

                $.ajax({
                    url: "/admin/subjects/getmentorsbysubjectid/" + subjectId,
                    dataType: "text",
                    success: function (data) {
                        $("#dialog-mentor-list").html(data);
                        $("#dialog-mentor-list").dialog({ height: 160 });
                        $("#dialog-mentor-list").dialog("open");
                    },
                    error: function (request, status, errorThrown) {
                        //$('#flash').html(request.responseText);
                        //$('#flash').toggleClass('info-error');
                        //$('#flash').slideDown('slow');
                        //$('#flash').click(function () {
                        //   $('#flash').toggle('highlight')
                        //});
                        $("#dialog-mentor-list").html(request.responseText);
                        $("#dialog-mentor-list").dialog({ height: 120 });
                        $("#dialog-mentor-list").dialog("open");

                    }
                });

            });
        });

        function reloadPage() { location.reload(true); }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Subjects
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>
        Subject List</h3>
    <input type="button" value="Add Subject" onclick="window.open('/admin/subjects/add/','_self')"
        class="button-style" />
    <br />
    <br />
    <%=Html.Grid(Model.SubjectList).Columns(column =>
      {
          column.For(x => x.SubjectCode).Sortable(true);
          column.For(x => x.SubjectName).Sortable(true);
          column.For(x => Html.ActionLink("Edit", "Edit", new { id = x.SubjectId }));
          column.For(x => Html.ActionLink("Delete", "Delete", new { id = x.SubjectId }, new { @class = "delete-subject-link" }));
          column.For(x => Html.ActionLink("View Lessons", "Index", new { Controller = "Lessons", id = x.SubjectId }, new {@class = "choose-mentor" , id = "lessonsbj-"+x.SubjectId }));
          column.For(x => Html.ActionLink("View Quizzes", "Index", new { Controller = "Quizzes", id = x.SubjectId }, new { @class = "choose-mentor", id = "quizsbj-" + x.SubjectId }));
      }).Sort(Model.GridSortOptions)
            .Attributes(@id => "grid-style" , cellspacing => "0",cellpadding => "0")
            .Empty("No subjects")%>
    <div class="event-paging">
        <div class="pager">
            <% if (Model.SubjectList.TotalItemCount > Model.SubjectList.PageSize)
               {%>
            <%= Html.Pager(Model.SubjectList.PageSize, Model.SubjectList.PageNumber, Model.SubjectList.TotalItemCount)%>
            <%} %>
        </div>
    </div>
    <div id="dialog-confirm" title="Delete this subject?" style="display: none;">
        <p>
            Are you sure you want to delete this subject? Lessons under this subject will also
            be deleted</p>
    </div>
    <div id="dialog-mentor-list" title="Choose a mentor" style="display: none;">
    </div>
</asp:Content>
